package com.think.teaching.utils.exception;

import javax.servlet.http.HttpServletRequest;

import org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException;
import org.apache.tomcat.util.http.fileupload.impl.SizeLimitExceededException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.multipart.MultipartException;

import com.think.common.model.Result;
import com.think.common.model.ResultCode;



@RestControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
	private final Logger logger = LoggerFactory.getILoggerFactory().getLogger("");
	@ExceptionHandler(MissingServletRequestParameterException.class)
	public Result ParamsMissExeption(
			MissingServletRequestParameterException  exception) {
		exception.printStackTrace();
		logger.error(exception.getParameterName() + "  has missing");
		Result result= Result.failure( ResultCode.PARAM_NOT_COMPLETE);
		result.setMsg(exception.getParameterName() + "  has missing");
		return result;
	}

	
	

	
	@ExceptionHandler(MaxUploadSizeExceededException.class)
	public Result MaxUploadSizeExceededException(
			MaxUploadSizeExceededException  exception) {
		return Result.failure(ResultCode.FILE_TOO_BIG);
		
	}

	@ExceptionHandler(SizeLimitExceededException.class)
	public Result SizeLimitExceededException(
			SizeLimitExceededException  exception) {
		return Result.failure(ResultCode.FILE_TOO_BIG);
		
	}
	@ExceptionHandler(Exception.class)
    public void myexce(Exception e) {
        System.out.println("myexce>>>"+e.getMessage());
    }

}
